
<template>
    <section>
        <div id='stacked-line-chart' class="h-[500px] w-[500px]"></div>
    </section>
</template>

<script lang='ts' setup>
import * as echarts from "echarts";

type Props = {
    dataType: string[]
    dataX: string[],
    dataY: any[],
}
const props = withDefaults(defineProps<Props>(), {
    dataType: () => [],
    dataX: () => [],
    dataY: () => [],
});

const initChart = () => {
    const chartDom = document.getElementById('stacked-line-chart');
    if (!chartDom) return
    const myChart = echarts.init(chartDom);
    let option = null;
    option = {
        // title: {
        //     text: '折线图走势',
        //     textStyle: {
        //         color: '#fff',
        //     }
        // },
        tooltip: {
            trigger: 'axis'
        },
        legend: {
            data: props.dataType,
            textStyle: {
                color: '#fff',
            }
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            boundaryGap: false,
            data: props.dataX,
            axisLabel: {
                inside: false,
                rotate: 60,
                color: '#fff'
            },
        },
        yAxis: {
            type: 'value'
        },
        color: ['#12c2e9', '#c471ed', '#f64f59', '#2980b9', '#6dd5fa', '#ffffff'],
        series: props.dataY,
    };
    option && myChart.setOption(option);
}

setTimeout(() => {
    initChart()
}, 500)
</script>

<style lang='scss' scoped></style>